﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kokomo.Mirror.CliMetadata.Signatures;
using System.Reflection;

namespace Kokomo.Mirror.CliMetadata
{
	class CliGenericMethodInfo : CliImplementedMethodInfo
	{
		private CliMethodInfo _definition;
		private Type[] _genericArguments;

		internal CliGenericMethodInfo(
			CliMemberBasicInfo basicInfo,
			CliMethodInfo definition,
			string name,
			Type[] genericArguments
			)
			: base(basicInfo, name)
		{
			this._definition = definition;
			this._genericArguments = genericArguments;
		}

		public override bool IsGenericMethod
		{
			get { return true; }
		}

		public override Type[] GetGenericArguments()
		{
			return this._genericArguments;
		}

		protected internal override MethodDefSignature GetSignature()
		{
			return this._definition.GetSignature();
		}

		public override System.Reflection.MethodAttributes Attributes
		{
			get { return this._definition.Attributes; }
		}

		public override System.Reflection.MethodImplAttributes GetMethodImplementationFlags()
		{
			return this._definition.GetMethodImplementationFlags();
		}

		protected override ParameterInfo[] LoadParameters(out ParameterInfo returnParameter)
		{
			return this.basicInfo.module.QueryParameters(
				CodedIndex.FromToken(this.MetadataToken).RowNumber,
				this,
				this.GetSignature(),
				out returnParameter
				);
		}

		public override System.Reflection.MethodInfo GetGenericMethodDefinition()
		{
			return this._definition;
		}
	}
}
